package com.stylefeng.guns.common.enums;

import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * 预测结果枚举
 *
 * @author wuchong
 */
public enum DxResultEnum {

    /**
     * 不预测
     */
    NONE("0", "不预测"),

    /**
     * 不预测
     */
    CHECKED("1", "预测失败"),

    /**
     * 大2.5
     */
    BIG("2", "大2.5"),

    /**
     * 小2.5
     */
    SMALL("3", "小2.5");

    /**
     * 缓存
     */
    private static final Map<String, DxResultEnum> MAP = Arrays
            .stream(DxResultEnum.values())
            .collect(Collectors
                    //转变为有序map
                    .toMap(DxResultEnum::getCode,
                            Function.identity()));
    /**
     * 键值对map
     */
    private static final Map<String, String> KEY_VALUE_MAP = Arrays
            .stream(DxResultEnum.values())
            .collect(Collectors
                    //转变为有序map
                    .toMap(DxResultEnum::getCode,
                            DxResultEnum::getDescription,
                            (k1, k2) -> k1,
                            LinkedHashMap::new));

    /**
     * 参数英文名
     */
    private String code;

    /**
     * 参数名
     */
    private String name;

    DxResultEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return name;
    }

    public static String getNameByCode(String code) {

        if (MAP.get(code) != null) {
            return MAP.get(code).name;
        }
        return null;
    }

    /**
     * 获取Key-Value对
     *
     * @return
     */
    public static Map<String, String> getKeyValue() {
        return KEY_VALUE_MAP;
    }
}
